1. Field of the Invention
The present invention relates to a picture coding apparatus, and more particularly to a picture coding apparatus encoding a digital picture data.
2. Description of the Related Art
As the technique for encoding picture data in the high efficiency, a motion compensation interframe prediction coding system is conventionally standardized and widely used (for example, MPEG and so on). The system uses the property that the correlation between video signals of continuing frames is generally large. Only the differential signal between a current frame (hereinafter, to be referred to as a predicted frame) and the past or future frame (hereinafter, to be referred to as a reference frame) is coded to reduce temporal redundancy.
In such an motion compensation interframe prediction coding system, the previously coded reference frame is moved based on a motion vector and the moved reference frame is used for an prediction signal. Subsequently, the difference value (hereinafter, to be referred to as a motion vector) between the prediction signal and a signal for the current frame is encoded. Thus, the increase of the code amount caused by the change of picture data is restrained.
Here, a general image processing will be described using MPEG as an example.
FIGS. 7A to 7F are diagrams showing the image processing in the MPEG. As shown in FIG. 7A, the whole video program is referred as an image sequence and is composed of a plurality of GOPs (Group Of Pictures). The image sequence starts with a sequence header (not shown) and ends with a sequence end (not shown). Data of the whole image sequence such as a data indicative of the size of the picture, the number of frames to be coded for one second, and a communication rate are stored in the sequence header.
The GOP is composed of a GOP header (not shown) and a plurality of pictures following the GOP header. Each picture is either of an I picture, a P picture, and a B picture. The I picture is the picture which is coded using only the picture signal in the frame. The P picture is the picture which is predicted from the coded picture (I or P picture) immediately before the P picture and is used for the motion prediction only in the front direction in the image sequence. The B picture is the picture which is predicted from two neighbor coded pictures (I and/or P pictures) and is used for the motion prediction in the front and back directions. It should be noted that the B picture is not used for the prediction of another picture.
Also, each picture corresponds to each screen of a picture signal and is composed of a picture header (not shown) and a plurality of slices following the picture header. Each slice is composed of a plurality of macro blocks. The macro block is composed of pixel blocks of 16 pixelsxc3x9716 pixels.
Next, a conventional motion compensation interframe prediction coding apparatus will be described. FIG. 1 is a block diagram showing a conventional motion compensation interframe prediction coding apparatus. As shown in FIG. 1, the conventional apparatus is composed of an input buffer 102 with an input terminal 101, a subtracting circuit 103, a motion vector detecting unit 104, a motion compensating unit 105, a DCT unit 106, a quantization unit 107, a variable length coding unit 108, an inverse quantization unit 109, an inverse DCT unit 110, an adding circuit 111, a frame memory 112, a vector coding unit 113, and a multiplexing unit 114.
An input picture data is supplied to and stored in the input buffer 102 via the input terminal 101. The input buffer 102 supplies the stored picture data to the subtracting circuit 103 and the motion vector detecting unit 104 in units of predetermined pixel blocks (i.e., in units of the above-mentioned macro blocks). The subtracting circuit 103 is supplied with the picture data outputted from the input buffer 102 and a block data (a reference macro block data) of a reference frame which is subjected to the motion compensation by the motion compensating unit 105. The subtracting circuit 103 determines an interframe differential signal using them and supplies to the DCT unit 106.
After the DCT unit 106 carries out a DCT (discrete cosine transformation) process to the supplied interframe differential signal to separate the frequency components in the horizontal and vertical directions, and to output the separated components to the quantization unit 107. The quantization unit 107 quantizes the output of the DCT unit 106 to reduce a bit rate and supplies the quantized data to the variable length coding unit 108 and the inverse quantization unit 109. The inverse quantization unit 109 inversely quantizes the output of the quantization unit 107 and then supplies to the inverse DCT unit 110.
The inverse DCT circuit 110 carries out an inverse DCT process to the output of the inverse quantization unit 109 and then supplies to the adding circuit 111. That is, a decoding process is carried out by the inverse quantization unit 109 and the inverse DCT unit 110, and a data similar to the interframe differential signal before the coding is obtained. The adding circuit 111 is supplied with the block data of the reference frame which is subjected to the motion compensation by the motion compensating unit 105 and the output of the inverse DCT unit 110. The adding circuit 111 adds them to reproduce the predicted block data of a current frame. The predicted block data is supplied to the frame memory 112.
The frame memory 112 stores the supplied block data and then supplies to the motion compensating unit 105 and the motion vector detecting unit 104 as the data of a new reference frame. The motion vector detecting unit 104 is supplied with the block data of the current frame from the input buffer 102, and the block data of the reference frame from the frame memory 112. The motion vector detecting unit 104 detects the motion vector between the reference frame and the current frame using the block data supplied thereto and supplies the detected motion vector to the motion compensating unit 105.
The block data of the reference frame is supplied from the frame memory 112 to the motion compensating circuit 105. Therefore, the motion compensating circuit 105 carries out motion compensation to the block data of the reference frame based on the motion vector from the motion vector detecting circuit 104. The motion compensating circuit 105 produces and supplies the block data of the reference frame subjected to the motion compensation (the reference macro block data) to the subtracting circuit 103.
On the other hand, the variable length coding unit 108 encodes the output of the quantization unit 107 into a variable length code and supplies the variable length code to the multiplexing unit 114. The vector coding unit 113 encodes the motion vector detected by the motion vector detecting unit 104 into a variable length code to supply to the multiplexing unit 114. The multiplexing unit 114 multiplexes the motion vector value encoded in the variable length code by the vector coding unit 113 as a header data and the picture data encoded in the variable length code by the variable length coding unit 108 and output the multiplexed code.
Next, the operation principle of such an motion compensation interframe prediction coding apparatus will be described.
FIGS. 2A to 2C are diagrams showing a reference frame and a predicted frames when an object moves to a direction at a constant speed. Generally, the movement of the object in the picture is felt as if it is very complicated as movement of a person in a TV picture. However, when the change of the picture is considered in units of pixels, it is not always correct. Because the motion compensation is carried out in units of predetermined pixel blocks, most of the pixels changes almost at the constant speed in compression of a picture, as shown in FIGS. 2B and 2C. Therefore, it could be considered that the motion vector becomes large in proportional to the distance from the reference frame. Thus, it would be valid that a motion vector search region is determined in accordance with the distance between the predicted frame and the reference frame in the motion compensation interframe prediction coding apparatus.
For example, it is supposed that the search region of the motion vector (x1,y1) of a predicted frame 1 is:
xe2x88x92r less than x1 less than r and xe2x88x92r less than y1 less than r
where r is an optional natural number. In this case, the motion vector search region of a predicted frame 2 is at least:
xe2x88x922r less than x2 less than 2r and xe2x88x922r less than y2 less than 2r
As an example of the motion compensation interframe prediction coding apparatus in which a search region is expanded in accordance with the distance between the reference frame and the predicted frame, there are known the apparatuses disclosed in Japanese Laid Open Patent Application (JP-A-Heisei 1-166684) and Japanese Laid Open Patent Application (JP-A-Heisei 10-336666).
In these conventional apparatuses, a search region is not simply made wide in accordance with the distance between the reference frame and the predicted frame, but the search region is appropriately adjusted. That is, an offset is set to the center position of the search region of the previously set motion vector in accordance with the values of the motion vectors in the past coded frames. Thus, the search region is shifted without changing the size of the search region, to apparently expand the motion vector search region.
However, when Huffman coding is carried out to allocate a variable length code to each of the motion vectors, a huge table is necessary because the motion vector has a wide dynamic range. As mentioned above, it is considered that the value of the motion vector is proportional to the distance between the predicted frame and the reference frame. Therefore, it would be efficient if the motion vector is divided into a first portion which does not depend on the distance between the frames, and a second portion which depends on the distance between the frames. A variable length code is allocated to the first portion and another coding method is applied to the second portion.
In the MPEG system defined in the international standard for the picture coding, a variable length code is allocated to a value in a range of xe2x80x9cxe2x88x9216 to +16xe2x80x9d as xe2x80x9cmotion_codexe2x80x9d for the coding which does not depend on the frame interval. Also, a parameter called xe2x80x9cf_codexe2x80x9d is used for the coding which depends on the frame interval.
The following table 1 shows the correspondence of the value of motion_code and the variable length code. The number of bits in the variable length code is decreased as the value approaches xe2x80x9c0xe2x80x9d and increased as the value layers from xe2x80x9c0xe2x80x9d as shown in the table 1.
The following table 2 shows a relation between f_code and the motion vector search region, the search region is expanded in proportional to square of 2, each time the value of f_code increases, as shown in this table.
On the other hand, the MPEG system adopts a differential encoding system to encode a difference (hereinafter, referred to as a differential motion vector) between a current motion vector and a previous motion vector which are for the macro blocks adjacent to each other in the same frame. Generally, the values of the neighbor motion vectors are similar. Therefore, the value of the differential motion vector nearer to xe2x80x9c0xe2x80x9d is frequently generated. Therefore, the coding efficiency can be improved when a short code is allocated to the differential motion vector value nearer to xe2x80x9c0xe2x80x9d, as shown in the table 1. When the range of the differential motion vector value is xe2x80x9cxe2x88x9216 to +15xe2x80x9d, the differential motion vector value should be coded using the table 1, just as it is.
However, when the differential motion vector value is in range of xe2x80x9cxe2x88x9232 to +31xe2x80x9d, the differential motion vector value can not be expressed using only the table 1. Therefore, a fixed length code is added to the variable length code shown in the table 1, so that the differential motion vector value can be expressed. That is, the following table 3 is referred to to determine the value of the fixed length code and the value of motion_code for the differential motion vector value. A variable length code corresponding to the determined motion_code is retrieved from the table 1 and the above-mentioned fixed length code is added after the selected variable length code.
For example, it is supposed that the differential motion vector value is xe2x80x9c4xe2x80x9d. In this case, as seen from the table 3, the fixed length code is xe2x80x9c1xe2x80x9d and the motion_code is xe2x80x9c2xe2x80x9d. Therefore, if being referred to the table 1, the variable length code for motion_code of xe2x80x9c2xe2x80x9d is xe2x80x9c0010xe2x80x9d. Thus, the code xe2x80x9c00101xe2x80x9d is determined by adding the above-mentioned fixed length code of xe2x80x9c1xe2x80x9d to xe2x80x9c0010xe2x80x9d.
It should be noted that the above process can be applied in the similar manner, when the differential motion vector value is in a range of xe2x80x9cxe2x88x9264 to +63xe2x80x9d. After a 2-bit fixed length code and a motion_code are determined by referring to the following table 4, a variable length code corresponding to the determined motion_code is determined by referring to the table 1, and then the fixed length code is added to the selected variable length code.
In this way, in the MPEG system, the value of f_code is increased in accordance with the distance between the reference frame and the predicted frame so that the motion vector search region can be expanded proportionally.
However, in such a conventional method to determine the value of f_code in accordance with the frame distance between the reference frame and the predicted frame, it is not always possible to efficiently encode the motion vector in all types of pictures.
For example, when the differential motion vector value of xe2x80x9c1xe2x80x9d is coded, the code has the length of 3 bits (xe2x80x9c010xe2x80x9d) if f_code=1, whereas the code has the length of 4 bit (xe2x80x9c0100xe2x80x9d) if f_code=2. Also, when the differential motion vector value of xe2x80x9c4xe2x80x9d is coded, the code has the length of 7 bits (xe2x80x9c0000110xe2x80x9d) if f_code=1, whereas the code has the length of only 5 bits (xe2x80x9c00101xe2x80x9d), if f_code=2. That is, the coding using f_code=1 is efficient, if the differential motion vector value falls within a range shown for f_code=1 and the generation distribution of differential motion vector values is centered in the neighborhood of xe2x80x9cxc2x11xe2x80x9d, as the result of the motion vector detection in the frame allocated to f_code=2. On the other hand, the generation distribution of differential motion vector values is centered in the neighborhood of xe2x80x9cxc2x14xe2x80x9d, the differential motion vector value can be efficiently coded when f_code=2 is used.
When the coding efficiency of the motion vector value is low, the quantity of codes allocated to the picture data is decreased so that the picture quality is degraded. Therefore, how to determine f_code is important. In this way, when f_code is simply determined in accordance with the distance of the reference frame and the predicted frame, the coding efficiency of the motion vector value is degraded. As a result, the quantity of codes allocated to the picture data is decreased and the picture quality is degraded.
In conjunction with the above description, a coding system of a motion-compensated motion vector is disclosed in Japanese Patent No. 2,537,242. In this reference, a memory (1) stores a predetermined number of input motion vectors. A code book (2) stores a plurality of previously determined motion vector patterns. A matching determination circuit (3) compares the input motion vector and the motion vector pattern to select the motion vector pattern having the smallest error, and to send the index to an entropy encoder (10). Thus, the coding system of the motion-compensated motion vector encodes the input motion vector into a variable length code by the entropy encoder (10).
Also, o a coding system of a motion-compensated motion vector is disclosed in Japanese Patent No. 2,537,243. In this reference, a memory (1) stores a predetermined number of input motion vectors. A code book (2) stores a plurality of previously determined prediction error vector patterns. A predicting circuit (3) generates a predicted motion vector. A prediction error generating circuit (4) generates a set of prediction error vectors from the input motion vector and the predicted motion vector. A matching determination circuit (5) compares the set of prediction error vectors and the prediction error vector patterns to select one prediction error vector pattern having the smallest error, and to send its index to an entropy encoder (10). In this case, the predicting circuit (3) generates the predicted motion vector from a prediction error pattern obtained by multiplexing the indexes outputted from the matching determination circuit (5) and a previous predicted motion vector by a multiplexing circuit (6).
Also, a coding system of a motion-compensated motion vector is disclosed in Japanese Patent No. 2,537,244. In this reference, a code book (1) stores a plurality of prediction error patterns each of which is composed of a prediction error motion vector corresponding to a predetermined number of input screen blocks. A predicting circuit (2) generates a predicted motion vector pattern corresponding to the input screen block and stores the prediction error pattern corresponding to the predicted motion vector pattern in the form of index. A matching determination circuit (3) input the predicted motion vector pattern, compensates a previous screen described in a frame memory (12) to compare with the input screen, selects the predicted motion vector pattern with the smallest error, and sends the index of the prediction error pattern corresponding to the predicted motion vector pattern to a receiving side via an entropy encoder (10). The predicting circuit (2) generates the predicted motion vector pattern from a previous predicted vector pattern and the prediction error pattern obtained by decoding the index outputted from the matching determination circuit (3) by a decoder (4).
Also, an image coding apparatus is disclosed in Japanese Laid Open Patent Application (JP-A-Heisei 2-076493). In this reference, a motion vector of an inputted image are detected for every small block. A motion vector field for the whole image is calculated from the detected motion vectors. The motion vector for every small block is developed by use of the motion vector field. The developed motion vector is used for motion compensation interframe prediction, and the motion vector field is transmitted as a motion vector data.
Also, a coding system of a motion-compensated motion vector is disclosed in Japanese Laid Open Patent Application (JP-A-Showa 64-73986). In this reference, a code bock (1) stores a plurality of motion vector patterns composed of motion vectors for a predetermined number of input screen blocks. A matching determination circuit (2) compares a screen obtained by motion compensating a previous screen stored in a frame memory (12) in accordance with the motion vector pattern and an input screen, and selects one of the plurality of motion vector patterns which has the smallest error, and sends an index of the selected motion vector pattern to an entropy encoder (10).
Therefore, an object of the present invention is to provide a picture coding apparatus in which the coding quality of a picture can be improved.
Another object of the present invention is to provide a picture coding apparatus in which the coding efficiency of a picture can be increased.
Still another object of the present invention is to provide a picture coding apparatus in which a type of f_code is adaptively determined so that the coding efficiency of a picture can be increased.
Yet still another object of the present invention is to provide a picture coding apparatus in which a table is used so that a type of f_code is adaptively determined with short processing time.
In order to achieve an aspect of the present invention, a picture coding apparatus includes a motion vector detector, a vector code length optimizing section, a motion vector coding unit, a variable length coding section, and a multiplexing unit. The motion vector detector detects motion vectors between a current picture data and a reference picture data in units of macro blocks. The vector code length optimizing section determines one of a plurality of parameters based on a total quantity of vector codes for differential motion vectors obtained from the detected motion vectors. The vector code includes a vector variable length code and a vector fixed length code. The motion vector coding unit encodes each of the differential motion vectors into the vector code using the determined parameter. The variable length coding section encodes picture data difference into picture data variable length codes in units of macro blocks. The picture data difference indicates a difference between the current picture data and a data obtained by carrying out a motion compensation to the reference picture data based on the detected motion vectors. The multiplexing unit multiplexes the picture data variable length code and the fixed length code for every macro block. In this case, the vector variable length code is a value of motion_code in an MPEG system, and the vector fixed length code is a value of f_code in the MPEG system, and the determined parameter is a type of f_code.
The vector code length optimizing section determines parameter candidates from among the plurality of parameters based on the detected motion vectors, calculates the total quantity of vector codes for the differential motion vectors when each of the parameter candidates is used, and determines the parameter from among the parameter candidates based on the calculated total quantities of vector codes.
Also, the vector code length optimizing section may include a parameter table indicating a relation of a set of average of the differential motion vectors and a deviation of the differential motion vectors and the parameters. At this time, the vector code length optimizing section determines the average of the differential motion vectors, determines the deviation of the differential motion vectors, and refers to the parameter table based on the determined average and the determined deviation to determines the parameter.
Also, the vector code length optimizing section may include a parameter table indicating a relation of a set of average of the differential motion vectors and a distribution region of the differential motion vectors and the parameters. At this time, the vector code length optimizing section determines the distribution region of the differential motion vectors, determines the average of the differential motion vectors, and refers to the parameter table based on the determined average and the determined distribution region to determines the parameter.
In order to achieve another aspect of the present invention, a method of encoding a picture data in an MPEG system, is attained by detecting motion vectors between a current picture data and a reference picture data in units of macro blocks; by determining a specific one of a plurality of parameters based on a total quantity of vector codes for differential motion vectors obtained from the detected motion vectors, the vector code including a vector variable length code and a vector fixed length code; by encoding each of the differential motion vectors into the vector code using the determined specific parameter; by encoding picture data difference into picture data variable length codes in units of macro blocks, the picture data difference indicating a difference between the current picture data and a data obtained by carrying out a motion compensation to the reference picture data based on the detected motion vectors; and by multiplexing the picture data variable length code and the fixed length code for every macro block.
The vector variable length code is a value of motion_code, and the vector fixed length code is a value of f_code, and the determined specific parameter is a type of f_code.
The determining the specific parameter may include: determining parameter candidates from among the plurality of parameters based on the detected motion vectors; calculating the total quantity of vector codes for the differential motion vectors when each of the parameter candidates is used, and determining the specific parameter from among the parameter candidates based on the calculated total quantities of vector codes.
Also, the determining the specific parameter may include: determining the average of the differential motion vectors, determining the deviation of the differential motion vectors, and referring to a parameter table based on the determined average and the determined deviation to determines the specific parameter. Here, the parameter table indicates a relation of a set of average of the differential motion vectors and a deviation of the differential motion vectors and the parameters.
Also, the determining the specific parameter may include: determining the distribution region of the differential motion vectors; determining the average of the differential motion vectors; and by referring to a parameter table based on the determined average and the determined distribution region to determines the specific parameter, the parameter table indicating a relation of a set of average of the differential motion vectors and a distribution region of the differential motion vectors and the parameters.
In order to achieve still another aspect of the present invention, a recording medium in which a program is stored for a method of encoding differential motion vectors obtained from motion vectors. The method is accomplished by detecting motion vectors between a current picture data and a reference picture data in units of macro blocks; by determining a specific one of a plurality of parameters based on a total quantity of vector codes for differential motion vectors the vector code including a vector variable length code and a vector fixed length code; and by encoding each of the differential motion vectors into the vector code using the determined specific parameter.